#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MCP 计算服务
提供基本的加减乘除运算功能
"""

from mcp.server.fastmcp import FastMCP
from typing import Union

# 创建 MCP 服务实例
mcp = FastMCP("Calculator Server")

@mcp.tool()
def add(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """加法运算"""
    return a + b

@mcp.tool()
def subtract(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """减法运算"""
    return a - b

@mcp.tool()
def multiply(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """乘法运算"""
    return a * b

@mcp.tool()
def divide(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
    """除法运算"""
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

# 启动服务
if __name__ == "__main__":
    mcp.run(transport="stdio")